import {Office} from "../../models/office";

Page({
  data: {
    latitude: 0,//纬度
    longitude: 0,
    markers: [],
    mapCtx: null,
    query: {
      pageNum: 1,
      pageSize: 10
    }
  },

  async onLoad(options) {
    const res = await Office.doApiGetOfficeInfo(this.data.query)
    const gps = res.rows[0].gps.split(',')
    console.log(gps)
    const obj = {
      latitude: gps[0],
      longitude: gps[1],
      name: 'xxx',
      id: 0,
      width: 30,
      height: 40
    }
    // const markerLatitude = this.data.markers[0].latitude
    // const markerLongitude = this.data.markers[0].longitude
    this.setData({
      latitude: +gps[0],
      longitude: +gps[1],
      ['markers[0]']: obj
    })
    console.log(this.data.markers)
    this.data.mapCtx = wx.createMapContext('mapId')
  },
  bindMarkerTap(e) {
    console.log(e);
  },
  openApp(e) {
    this.data.mapCtx.openMapApp({
      latitude: this.data.latitude,
      longitude: this.data.longitude,
      destination: '达州市渠县财政大厦',
      success: res => {
        console.log(res);
      }
    })
  }
})
